package com.hcbd.tdwt.ui.xingyu.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


import com.hcbd.tdwt.R;
import com.hcbd.tdwt.base.BaseActivity;
import com.hcbd.tdwt.ui.xingyu.vo.BoxContact;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

@SuppressLint("NonConstantResourceId")
@EActivity(R.layout.activity_add_contact)
public class AddContactActivity extends BaseActivity {
    //联系人名称
    @ViewById
    EditText addContactNameEdit;
    //联系人北斗卡
    @ViewById
    EditText addContactBoxCardIdEdit;
    //保存
    @ViewById
    Button saveBtn;
    @ViewById
    TextView title;

    private int entryMode=0;
    private BoxContact boxContact;
    @AfterViews
    protected void init() {
        initData();
    }
    void initData(){
         entryMode=getIntent().getIntExtra("entryMode",0);
        if(entryMode==1) {
            title.setText("编辑联系人");
            boxContact = (BoxContact)getIntent().getSerializableExtra("boxContact");
            if(boxContact==null){
                toast("程序有误!");
                finish();
                return;
            }
            addContactNameEdit.setText(boxContact.getName());
            addContactBoxCardIdEdit.setText(boxContact.getBoxId());
        }
    }
    @Click
    void saveBtn(){
        String name = getTextStr(addContactNameEdit);
        String boxCardId = getTextStr(addContactBoxCardIdEdit);
        if (TextUtils.isEmpty(boxCardId)) {
            popupMsg("北斗卡号不能为空");
            return;
        }
        if (TextUtils.isEmpty(name)) {
            popupMsg("联系人名称不能为空");
            return;
        }
        if(entryMode==1){
            boxContact.setBoxId(boxCardId);
            boxContact.setName(name);
            boxContact.update();
        }else{
            BoxContact.upData(boxCardId, name, "已添加联系人，快发送消息吧",0);
        }
        hideKeyboard();
        setResult(Activity.RESULT_OK);
        finish();
    }


    @Click
    void headLeft(){
        hideInputKeyBord();
        finish();
    }



}
